00001
00002
00003
00004
00005
00006 #ifndef _local_timer_h
00007 #define _local_timer_h
00008
00009 #include <map>
00010 #include <string>
00011 #include <vector>
00012 #include <fstream>
00013
00014 #include <boost/smart_ptr/shared_ptr.hpp>
00015 #include <boost/serialization/export.hpp>
00016 #include "gridpack/parallel/distributed.hpp"
00017
00018
00019
00020 namespace gridpack{
00021 namespace utility{
00022
00023 class LocalTimer
00024 : public gridpack::parallel::Distributed {
00025 public:
00026
00027
00028
00029
00030 LocalTimer(const gridpack::parallel::Communicator &comm);
00031
00032
00033
00034
00035 ~LocalTimer();
00036
00037
00038
00039
00040
00041
00042
00043
00044 int createCategory(const std::string title);
00045
00046
00047
00048
00049
00050 void start(const int idx);
00051
00052
00053
00054
00055
00056 void stop(const int idx);
00057
00058
00059
00060
00061 void dump(void) const;
00062
00063
00064
00065
00066 void dump(boost::shared_ptr<std::ofstream> stream) const;
00067
00068
00069
00070
00071
00072 void dumpProfile(const int idx) const;
00073
00074
00075
00076
00077
00078 void dumpProfile(const std::string title);
00079
00080
00081
00082
00083
00084
00085 double currentTime();
00086
00087
00088
00089
00090
00091 void configTimer(bool flag);
00092
00093 private:
00094
00095 std::map<std::string, int> p_title_map;
00096 std::vector<std::string> p_title;
00097 std::vector<double> p_start;
00098 std::vector<double> p_time;
00099 std::vector<int> p_istart;
00100 std::vector<int> p_istop;
00101
00102 bool p_profile;
00103 };
00104
00105
00106 }
00107 }
00108
00109 BOOST_CLASS_EXPORT_KEY(gridpack::utility::LocalTimer)
00110
00111 #endif // _local_timer_h